﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.IO;

namespace JohnnySins.Controls
{
    public partial class FtpVideoChoice : System.Web.UI.UserControl
    {
        private string ftpPath = ConfigurationManager.AppSettings["FtpVideoPath"];
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void LoadData()
        {
            List<string> files = new List<string>();
            DirectoryInfo di = new DirectoryInfo(ftpPath);
            foreach (FileInfo fi in di.GetFiles())
            {
                files.Add(fi.Name);
            }
            files.Sort();
            grid.DataSource = files;
            grid.DataBind();
        }

        protected void upVideoChoice_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request["__EVENTTARGET"]))
                if (Request["__EVENTTARGET"] != upVideoChoice.ClientID)
                    return;

            if (!string.IsNullOrEmpty(Request["__EVENTARGUMENT"]))
            {
                hdFuId.Value = Request["__EVENTARGUMENT"];
                LoadData();
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "ShowFtpDialog", "showFtpVideoChoice();", true);
            }
        }
    }
}